package main

import (
	"fmt"
	"net/http"
	"runtime"
	"strings"
)

func OkHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Welcome!")
}
func HealthzHandler(w http.ResponseWriter, r *http.Request) {
	if len(r.Header) > 0 {
		for k, v := range r.Header {
			fmt.Printf("req header: %s=%s\n", k, v)
			vv := strings.Join(v, ",")
			w.Header().Set(k, vv)
		}
		w.Header().Set("go-version", runtime.Version())
		w.Header().Set("test", "test")
		w.WriteHeader(500)
		w.Write([]byte("hello world!\n")) //问题：不清楚为什么在14-18行放开后，此行就不生效了？
	}

}

func main() {
	//路由
	http.HandleFunc("/", OkHandler)
	http.HandleFunc("/healthz", HealthzHandler)

	err := http.ListenAndServe(":80", nil)
	if err != nil {
		panic(err)
	}

}